package data

import (
	"database/sql/driver"
	"encoding/json"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

type Version struct {
	ID                int
	Name              string
	CategoryTypeId    int
	BrandId           int
	BrandModelId      int
	EnergyTypeId      int
	EngineTypeId      int
	GearboxTypeId     int
	DriveWayTypeId    int
	OfficialPrice     float64 `json:"official_price" sql:"type:decimal(10,2);"`
	XbPerkPrice       float64 `json:"xb_perk_price" sql:"type:decimal(10,2);"`
	ReturnPointsPrice float64 `json:"return_points_price" sql:"type:decimal(10,2);"`
	Classify          string
	StyleYear         string
	Displacements     string
	StandardTypeId    int
	Horsepower        string
	Images            string
	ParamConfig       string
	Sort              int
	Status            int
	CreatedAt         time.Time
	UpdatedAt         time.Time
	FirstImage        string
}

func (Version) TableName() string {
	return "life_car_brand_model_versions"
}

type Config struct {
	Name      string      `json:"name"`
	SubConfig []SubConfig `json:"sub_config"`
}

type SubConfig struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

// Value 实现方法
func (p Config) Value() (driver.Value, error) {
	return json.Marshal(p)
}

// Scan 实现方法
func (p Config) Scan(input interface{}) error {
	return json.Unmarshal(input.([]byte), &p)
}
